/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuPrincipal.java
 *
 * Created on 12-dic-2011, 11:41:20
 */
package edu.uoc.tdp.client;

import edu.uoc.tdp.common.EIssueException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author scastillon J2RS
 */
public class MenuPrincipal extends javax.swing.JFrame {

    /** Creates new form MenuPrincipal */
    public MenuPrincipal() {
        initComponents();
        
        MnUsers.setEnabled(false);
        MnSpaces.setEnabled(false);
        MnResources.setEnabled(false);
        MnBooking.setEnabled(false);
        MnNewBooking.setEnabled(false);  
                    
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();
        MnExit = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        MnUsers = new javax.swing.JMenuItem();
        MnSpaces = new javax.swing.JMenuItem();
        MnResources = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        MnNewBooking = new javax.swing.JMenuItem();
        MnBooking = new javax.swing.JMenuItem();
        jMenu8 = new javax.swing.JMenu();
        jMenu6 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jMenu2.setText("File");

        MnExit.setText("Exit");
        MnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnExitActionPerformed(evt);
            }
        });
        jMenu2.add(MnExit);

        jMenuBar1.add(jMenu2);

        jMenu1.setText("Management");

        MnUsers.setText("Users");
        MnUsers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnUsersActionPerformed(evt);
            }
        });
        jMenu1.add(MnUsers);

        MnSpaces.setText("Spaces");
        MnSpaces.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnSpacesActionPerformed(evt);
            }
        });
        jMenu1.add(MnSpaces);

        MnResources.setText("Resources");
        MnResources.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnResourcesActionPerformed(evt);
            }
        });
        jMenu1.add(MnResources);

        jMenuBar1.add(jMenu1);

        jMenu5.setText("Bookings");

        MnNewBooking.setText("New Booking");
        MnNewBooking.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnNewBookingActionPerformed(evt);
            }
        });
        jMenu5.add(MnNewBooking);

        MnBooking.setText("Booking");
        MnBooking.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnBookingActionPerformed(evt);
            }
        });
        jMenu5.add(MnBooking);

        jMenuBar1.add(jMenu5);

        jMenu8.setText("Statistics");
        jMenu8.setEnabled(false);
        jMenuBar1.add(jMenu8);

        jMenu6.setText("About");
        jMenuBar1.add(jMenu6);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1024, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 727, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnExitActionPerformed
        //System.exit();
    }//GEN-LAST:event_MnExitActionPerformed

    private void MnUsersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnUsersActionPerformed
        try {
            PanelUser pnll = null;
            pnll = new PanelUser(Boolean.TRUE);
            //pnll.setTitle(TDPLanguageUtils.getMessage(TDPLanguageConstants.MAIN_FORM_TITLE));
            //pnll.setLocationRelativeTo(null);
            pnll.setSize(1024,748);
            //ppl.setDefaultCloseOperation(PanelUser.EXIT_ON_CLOSE);
            pnll.setVisible(true);
        } catch (RemoteException ex) {
            Logger.getLogger(MenuPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (EIssueException ex) {
            Logger.getLogger(MenuPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_MnUsersActionPerformed

    private void MnSpacesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnSpacesActionPerformed
        try {
            PanelSpace pnll = null;
            pnll = new PanelSpace();
            //pnll.setTitle(TDPLanguageUtils.getMessage(TDPLanguageConstants.MAIN_FORM_TITLE));
            //pnll.setLocationRelativeTo(null);
            pnll.setSize(1024,748);
            //ppl.setDefaultCloseOperation(PanelUser.EXIT_ON_CLOSE);
            pnll.setVisible(true);
        } catch (RemoteException ex) {
            Logger.getLogger(MenuPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (EIssueException ex) {
            Logger.getLogger(MenuPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_MnSpacesActionPerformed

    private void MnNewBookingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnNewBookingActionPerformed
        PanelSearch pnll = null;
        pnll = new PanelSearch(Boolean.TRUE);
        //pnll.setTitle(TDPLanguageUtils.getMessage(TDPLanguageConstants.MAIN_FORM_TITLE));
        //pnll.setLocationRelativeTo(null);
        pnll.setSize(1024,748);
        //ppl.setDefaultCloseOperation(PanelUser.EXIT_ON_CLOSE);
        pnll.setVisible(true);
    }//GEN-LAST:event_MnNewBookingActionPerformed


    
    private void MnResourcesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnResourcesActionPerformed
        PanelResource pnll = null;
        try {
            pnll = new PanelResource();
        } catch (RemoteException ex) {
            Logger.getLogger(MenuPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
       
            
        
        pnll.setSize(1024,748);
        pnll.setVisible(true);
    }//GEN-LAST:event_MnResourcesActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        while (Client.availableUser==null){
            DialogLogin pnll = null;
            pnll = new DialogLogin(this,true);
            pnll.setVisible(true);
            EnableUserMenus();
        }
    }//GEN-LAST:event_formWindowOpened

    public void EnableUserMenus()
    {
        if (Client.availableUser!=null){
            switch (Client.availableUser.getRoleId()) {
                case -1:// No informat
                    MnUsers.setEnabled(false);
                    MnSpaces.setEnabled(false);
                    MnResources.setEnabled(false);
                    MnBooking.setEnabled(false);
                    MnNewBooking.setEnabled(false);                    
                    break;
                case 0:// Client
                    MnUsers.setEnabled(false);
                    MnSpaces.setEnabled(false);
                    MnResources.setEnabled(false);
                    MnBooking.setEnabled(true);
                    MnNewBooking.setEnabled(true);
                    break;
                case 1:// Tenic
                    MnUsers.setEnabled(false);
                    MnSpaces.setEnabled(false);
                    MnResources.setEnabled(false);
                    MnBooking.setEnabled(true);
                    MnNewBooking.setEnabled(true);
                    break;
                case 2:// Administrador
                    MnUsers.setEnabled(true);
                    MnSpaces.setEnabled(true);
                    MnResources.setEnabled(true);
                    MnBooking.setEnabled(true);
                    MnNewBooking.setEnabled(true);
                    break;
            }            
        }    
    }
    
    private void MnBookingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MnBookingActionPerformed
        // TODO add your handling code here:
                PanelBookings pnll = null;
        pnll = new PanelBookings(Boolean.TRUE);
        //pnll.setTitle(TDPLanguageUtils.getMessage(TDPLanguageConstants.MAIN_FORM_TITLE));
        //pnll.setLocationRelativeTo(null);
        pnll.setSize(1024,748);
        //ppl.setDefaultCloseOperation(PanelUser.EXIT_ON_CLOSE);
        pnll.setVisible(true);
    }//GEN-LAST:event_MnBookingActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MenuPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MenuPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MenuPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MenuPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MenuPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem MnBooking;
    private javax.swing.JMenuItem MnExit;
    private javax.swing.JMenuItem MnNewBooking;
    private javax.swing.JMenuItem MnResources;
    private javax.swing.JMenuItem MnSpaces;
    private javax.swing.JMenuItem MnUsers;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenu jMenu8;
    private javax.swing.JMenuBar jMenuBar1;
    // End of variables declaration//GEN-END:variables
}
